package com.zhaiweijia.nacosclient.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zhaiweijia.dto.UserDto;
import com.zhaiweijia.nacosclient.entity.User;
import com.zhaiweijia.nacosclient.service.IUserService;
import com.zhaiweijia.vo.ResultEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zhaiwj
 * @since 2021-02-22
 */
@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private IUserService iUserService;

    @RequestMapping("/list")
    public Object  getUserList(UserDto userDto) {
        QueryWrapper<User> queryWrapper = new QueryWrapper<>();
        PageHelper.startPage(userDto.getPageNum(),userDto.getPageSize());
        if(userDto.getName()!=null && userDto.getName()!=""){
            queryWrapper.like("name",userDto.getName());
        }

        List<User> userList = iUserService.list(queryWrapper);
        PageInfo<User> info = new PageInfo<>(userList);
        return  ResultEntity.ok("200","操作成功",info);
    }

}